/*
 * usea, Copyright 2011 André König
 * Hochschule Bremen - University of Applied Sciences - All Rights Reserved.
 *
 * $Id: ArticleService.java 17 2011-07-06 06:51:01Z andre.koenig $
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 * Contact:
 *     André König: akoenig@stud.hs-bremen.de
 * 
 * Web:
 *     http://tutorium-prog2.tumblr.com
 * 
 */
package de.hochschule.bremen.usea.server.service;

import java.util.Vector;

import de.hochschule.bremen.usea.commons.vo.Article;

public class ArticleService {

	private Vector<Article> articles = new Vector<Article>();
	
	public ArticleService() {
		// Erstellung von Artikel-Objekten.
		// Diese kommen normalerweise aus dem Storage-System (Persistence).
		// Werden also aus einer Datenbank bzw. aus einer Datei gelesen.
		this.articles.add(new Article(1, "Nutella", 12, 2.99));
		this.articles.add(new Article(2, "Becks", 6, 1.20));
		this.articles.add(new Article(2, "Colgate Zahncreme", 10, 1.20));
	}
	
	/**
	 * Gibt die gespeicherte Artikel-Liste zurueck.
	 *
	 * @return
	 */
	public Vector<Article> list() {
		return articles;
	}
	
	/**
	 * Ersetzt den gespeicherten Artikel mit dem uebergebenen Artikel.
	 *
	 * @param article Der zu speichernde Artikel.
	 *
	 */
	public void replace(Article wannabe) {
		search : for (Article article : this.articles) {
			if (article.getId() == wannabe.getId()) {
				this.articles.remove(article);
				
				break search;
			}
		}

	    this.articles.add(wannabe);
	}
}